﻿package com.inin.swing.jqchat.server;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import javax.swing.UIManager;

import com.inin.swing.jqchat.server.service.SQLServerProcess;
import com.inin.swing.jqchat.util.Param;
import com.inin.swing.jqchat.util.PropertyFile;

public class Server {
	public static void main(String[] args){
		try {
            com.jtattoo.plaf.mcwin.McWinLookAndFeel.setTheme("Modern", "", "my company");

            // Select the Look and Feel
            UIManager.setLookAndFeel("com.jtattoo.plaf.mcwin.McWinLookAndFeel");

        }
        catch (Exception ex) {
            ex.printStackTrace();
        }
		new SQLServerProcess(checkPropertyFile());
	}
	
	/**查看数据库配置文件是否存在*/
	private static PropertyFile checkPropertyFile(){
		File file = new File(Param.CURRENTPATH + Param.FILENAME);
		File dir = new File(Param.CURRENTPATH);
		//如果不存在则创建一个默认的
		if (!file.exists()) {
			dir.mkdirs();	//产生目录
			try {
				file.createNewFile();	//创建文件
				//PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(file)));
				FileWriter out = new FileWriter(file);
				out.write(Param.PROPERTYFILE);	//把默认的内容写进去
				out.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		
		return new PropertyFile(Param.CURRENTPATH + Param.FILENAME);
	}
}
